package com.yfree.views;

import android.app.ProgressDialog;

import com.yfree.activities.YActivity;
import com.yfree.views.svprogresshud.SVProgressHUD;

public class YProgressDialog {
    private static ProgressDialog progressDialog;
    private static SVProgressHUD progressDialog2;
    public static boolean isShowing = false;

    public static void showProgress(final YActivity context) {
        context.yRunOnUIThread(new Runnable() {
            @Override
            public void run() {
//                if (context.context instanceof YActivity) {
//                    try {
//                        progressDialog.dismiss();
//                    } catch (Exception ignored) {
//                    }
//                    progressDialog = new ProgressDialog(context);
//                    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
//                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && YConfig.logo_icon_progress != 0) {
//                        RotateDrawable rotateDrawable = new RotateDrawable();
//                        rotateDrawable.setDrawable(context.getResources().getDrawable(YConfig.logo_icon_progress));
//                        rotateDrawable.setFromDegrees(0);
//                        rotateDrawable.setPivotX(0.5f);
//                        rotateDrawable.setPivotY(0.5f);
//                        rotateDrawable.setToDegrees(360);
//                        progressDialog.setIndeterminateDrawable(rotateDrawable);
//                    }
//                    progressDialog.setMessage("拼命加载中，请稍后·····\t\t\t\t\t\t");
//                    progressDialog.setCancelable(false);
//                    progressDialog.setCanceledOnTouchOutside(YConfig.progressBarCancelable);
//                    try {
//                        progressDialog.show();
//                    } catch (Exception ignored) {
//                    }
//                } else {
                try {
                    progressDialog2.dismiss();
                } catch (Exception ignored) {
                }
                progressDialog2 = new SVProgressHUD(context.context);
                try {
                    progressDialog2.showWithStatus("拼命加载中···");
                } catch (Exception ignored) {
                }
                isShowing = true;
            }
        });
    }

    public static void dismissProgress(final YActivity context) {
        context.yRunOnUIThread(new Runnable() {
            @Override
            public void run() {
//                if (context.context instanceof YActivity) {
//                    try {
//                        progressDialog.dismiss();
//                        progressDialog = null;
//                    } catch (Exception ignored) {
//                    }
//                } else {
                try {
                    progressDialog2.dismiss();
                    progressDialog2 = null;
                } catch (Exception ignored) {
                }
                isShowing = false;
//                }
            }
        });
    }
}
